package action;

import gate.ActionHandler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dm.InvoiceDM;

import bean.invoice.Invoice;
import bean.user.SessionUser;

public class ActionInvoice implements ActionHandler{

	@Override
	public void handleAction(HttpServletRequest req, HttpServletResponse res) {

		try {
			String url = req.getParameter("URL");
			InvoiceDM dm = new InvoiceDM();
			HttpSession s = req.getSession();
			SessionUser user = (SessionUser) s.getAttribute("user");
			
			try {
				Invoice invoice = dm.printInvoice(user);
				req.setAttribute("invoice",invoice);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			req.getRequestDispatcher(url).forward(req, res);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
